package com.example.kafka;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

/**
 * @author lbq
 * @version 1.0
 * @date 2022/3/27 15:37
 */
public class KafkaConsumer {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        final Properties properties = new Properties();
        properties.setProperty("bootstrap.servers", "aliyun:9092");

        final FlinkKafkaConsumer<String> kafkaConsumer = new FlinkKafkaConsumer<>("flink-demo", new SimpleStringSchema(), properties);
        kafkaConsumer.setStartFromEarliest();

        final DataStreamSource<String> data = env.addSource(kafkaConsumer);
        data.print();

        env.execute();
    }
}
